<?php
/**
 * FileName: admin.php
 * Author: Fei.Song @cepcc
 * Date: 2021/2/24 15:03
 * Created by PhpStorm
 * Desc: 后台路由文件
 */

use Illuminate\Support\Facades\Route;

//后台登录
Route::get('admin/login', [\App\Http\Controllers\Admin\LoginController::class, 'loginShow'])->middleware('adminlogin')->name('admin.loginShow');
Route::post('admin/login', [\App\Http\Controllers\Admin\LoginController::class, 'login'])->name('admin.login');
Route::get('admin/change', [\App\Http\Controllers\Admin\LoginController::class, 'changeShow'])->middleware('adminlogin')->name('admin.changeShow');
Route::post('admin/change/{id}', [\App\Http\Controllers\Admin\LoginController::class, 'change'])->middleware('adminlogin')->name('admin.change');
Route::get('admin/logout', [\App\Http\Controllers\Admin\LoginController::class, 'logout'])->name('admin.logout');
Route::get('admin/already', [\App\Http\Controllers\Admin\LoginController::class, 'already'])->name('admin.login.already');
Route::post('/upload', [\App\Http\Controllers\UploadController::class, 'upload'])->middleware('adminlogin')->name('upload');


//后台页面/操作
Route::name('admin.')->prefix('admin')->middleware(["auth:admin", "adminlogin", "admininit", "routes"])->namespace("\App\Http\Controllers\Admin")->group(function () {
    //后台首页
    Route::name('index')->get('/', "IndexController@index");
    //用户相关路由
    Route::name('user.')->prefix('user')->group(function () {
        Route::name('index')->get('index', 'UserController@index');
        Route::name('create')->match(["get", "post"], 'create', 'UserController@create');

        Route::name('edit')->get('edit/{user}', 'UserController@edit');
        Route::name('update')->post('update/{id}', 'UserController@update')->withoutMiddleware(["routes"]);//权限规则待定
        Route::name('destroy')->get('destroy/{id}', 'UserController@destroy');//没有删除
        Route::name('search')->get('search/{key}', 'UserController@search')->withoutMiddleware(["routes"]);//权限规则待定
        Route::name('upload')->post('upload', 'UserController@upload')->withoutMiddleware(["routes"]);//权限规则待定
        Route::name('show')->get('show/{user}', 'UserController@show');
        Route::name('onoff')->get('onoff', 'UserController@isOpen');
        Route::name('role_form')->get('role_form/{user}', 'UserController@role_form');
        Route::name('role_assign')->post('assign/{user}', 'UserController@assign')->withoutMiddleware(["routes"]);//权限规则待定
        Route::name('change_pwd')->get('change_pwd/{user_id}', 'UserController@changePwdShow');
        Route::name('change_store')->post('change/{id}', 'UserController@changePwd')->withoutMiddleware(["routes"]);//权限规则待定
    });
    //角色相关
    Route::name('role.')->prefix('role')->group(function () {
        Route::name('index')->get('index', 'RoleController@index');
        Route::name('create')->get('create', 'RoleController@create');
        Route::name('store')->post('store', 'RoleController@store')->withoutMiddleware(["routes"]);//权限规则待定
        Route::name('show')->get('show/{role}', 'RoleController@show');
        Route::name('edit')->get('edit/{id}', 'RoleController@edit');
        Route::name('update')->post('update/{id}', 'RoleController@update')->withoutMiddleware(["routes"]);//权限规则待定
        Route::name('destroy')->get('destroy/{id}', 'RoleController@destroy');
        Route::name('per_form')->get('assign_form/{id}', 'RoleController@per_form');
        Route::name('permission_assign')->post('assign/{role_id}', 'RoleController@assign')->withoutMiddleware(["routes"]);//权限规则待定
    });
    //岗位管理相关
    Route::name('post.')->prefix('post')->group(function () {

        Route::name('index')->get('group/index', "PostController@groupIndex");
        Route::name('create')->match(['get', 'post'], 'group/create', "PostController@groupCreate");
        Route::name('update')->match(['get', 'post'], 'group/update', "PostController@groupUpdate");
        Route::name('destroy')->get('group/destroy/{id}', "PostController@groupDestroy");
        Route::name('changeSort')->post('group/changeSort', "PostController@changeGroupSort")->withoutMiddleware(["routes"]);

        Route::name('index.attach')->get('index', "PostController@index");
        Route::name('create.attach')->match(['get', 'post'], 'create', "PostController@create");
        Route::name('update.attach')->match(['get', 'post'], 'update', 'PostController@update');
        Route::name('destroy.attach')->get('destroy/{id}', 'PostController@destroy');
        Route::name('changeSort.attach')->post('changeSort', "PostController@changeSort")->withoutMiddleware(["routes"]);

    });
    //用户组管理相关
    Route::name('usergroup.')->prefix('usergroup')->group(function () {

        Route::name('index')->get('index', "UserGroupController@index");
        Route::name('create')->match(['get', 'post'], 'create', "UserGroupController@create");
        Route::name('update')->match(['get', 'post'], 'update', "UserGroupController@update");
        Route::name('destroy')->get('destroy/{id}', "UserGroupController@destroy");

        Route::name('index.attach')->get('user/index', "UserGroupController@userIndex");
        Route::name('create.attach')->post('user/create', "UserGroupController@userCreate");
        Route::name('destroy.attach')->get('user/destroy/{id}', "UserGroupController@userDestroy");

    });
    //考场管理相关
    Route::name('basic.')->prefix('basic')->group(function () {
        Route::name('index')->get('index', "BasicController@index");
        Route::name('create')->match(['get', 'post'], 'create', "BasicController@create");
        Route::name('update')->match(['get', 'post'], 'update', "BasicController@update");
        Route::name('destroy')->match(['get', 'post'], 'destroy', "BasicController@destroy");
        Route::name('setting')->match(['get', 'post'], 'setting', "BasicSettingController@setting");
        Route::name('create.attach')->match(['post'], 'upload', "BasicController@upload");

        Route::name('examindex')->get('exam/index', "BasicBatchController@index");
        Route::name('examcreate')->match(['get', 'post'], 'exam/create', "BasicBatchController@create");
        Route::name('examupdate')->match(['get', 'post'], 'exam/update', "BasicBatchController@update");
        Route::name('examdestroy')->match(['get'], 'exam/destroy', "BasicBatchController@destroy");

        Route::name('memberindex')->get('member/index', "BasicMemberController@index");
        Route::name('membercreate')->match(['get', 'post'], 'member/create', "BasicMemberController@create");
        Route::name('membercreate.attach')->match(['get', 'post'], 'member/condition', "BasicMemberController@condition");
        Route::name('memberdestroy')->match(['get'], 'member/destroy', "BasicMemberController@destroy");

    });
    //会员管理相关
    Route::name('member.')->prefix('member')->group(function () {

        Route::name('index')->get('index', "MemberController@index");
        Route::name('create')->match(['get', 'post'], 'create', "MemberController@create");
        Route::name('update')->match(['get', 'post'], 'update', "MemberController@update");
        Route::name('destroy')->match(['get', 'post'], 'destroy', "MemberController@destroy");
        Route::name('create.attach')->match(['post'], 'upload', "MemberController@upload");
        Route::name('create.attach.1')->match(['get', 'post'], 'profile', "MemberController@profile");
        Route::name('password')->match(['get', 'post'], 'password', "MemberController@password");
        Route::name('update.attach.1')->post('locked', "MemberController@isLocked");

    });
    //题库版本相关
    Route::name('version.')->prefix('version')->group(function () {

        Route::name('index')->get('index', "QuestionVersionController@index");
        Route::name('create')->match(['get', 'post'], 'create', "QuestionVersionController@create");
        Route::name('update')->match(['get', 'post'], 'update', "QuestionVersionController@update");
        Route::name('destroy')->get('destroy/{id}', "QuestionVersionController@destroy");
        Route::name('update.attach')->post('usable', "QuestionVersionController@usable");
    });
    //部门管理相关
    Route::name('org.')->prefix('org')->group(function () {
        Route::name('index')->get('index', "OrgController@index");
        Route::name('show')->get('show/{org}', "OrgController@show");
        Route::name('create')->get('create', "OrgController@create");
        Route::name('store')->post('store', "OrgController@store")->withoutMiddleware(["routes"]);//权限规则待定
        Route::name('edit')->get('edit/{org}', "OrgController@edit");
        Route::name('update')->post('update/{id}', "OrgController@update")->withoutMiddleware(["routes"]);//权限规则待定
        Route::name('select')->get('select', "OrgController@select")->withoutMiddleware(["routes"]);//权限规则待定
        Route::name('destroy')->get('destroy/{id}', "OrgController@destroy");
        Route::name('edit.attach.1')->get('sort/{id}/{sort}', "OrgController@setSort");
    });
    //科目相关
    Route::name('category.')->prefix('category')->group(function () {
        Route::name('index')->get('{groupId}/index', "CategoryController@index");
        Route::name('update.attach.1')->get('sort/{id}/{sort}', "CategoryController@setSort");
        Route::name('show')->get('show/{id}', "CategoryController@show");
        Route::name('create')->match(["get", "post"], 'create', "CategoryController@create");
        Route::name('update')->match(["get", "post"], 'edit', "CategoryController@edit");
        Route::name('destroy')->get('destroy/{id}', "CategoryController@destroy");
        Route::name('update.attach')->match(["get", "post"], 'settag/{id}', "CategoryController@settag");
        Route::name('update.attach.1')->match(["get", "post"], 'setversion/{id}', "CategoryController@setVersion");
    });

    //标签相关
    Route::name('tags.')->prefix('tags')->group(function () {
        //标签
        Route::name('index')->get('index', "TagController@index");
        Route::name('create')->match(["get", "post"], 'create', "TagController@create");
        Route::name('update')->match(["get", "post"], 'edit/{id}', "TagController@edit");
        Route::name('destroy')->get('destroy/{id}', "TagController@destroy");

        //标签组
        Route::name('index.attach')->get('group/index', "TagController@tagGroup");
        Route::name('create.attach')->match(["get", "post"], 'group/create', "TagController@groupCreate");
        Route::name('update.attach')->match(["get", "post"], 'group/update/{id}', "TagController@groupEdit");
        Route::name('destroy.attach')->get('group/destroy/{id}', "TagController@groupDestroy");

    });


    //职级管理相关
    Route::name('level.')->prefix('level')->group(function () {
        Route::name('index')->get('index', function () {
            return Route:: currentRouteName();
        });
        Route::name('create')->get('create', function () {
            return Route:: currentRouteName();
        });
        Route::name('store')->post('store', function () {
            return Route:: currentRouteName();
        });
        Route::name('edit')->get('edit', function () {
            return Route:: currentRouteName();
        });
        Route::name('update')->post('update', function () {
            return Route:: currentRouteName();
        });
        Route::name('destroy')->get('destroy/{id}', function ($id) {
            return $id . Route:: currentRouteName();
        });
    });

    //操作日志相关
    Route::name('log.')->prefix('log')->group(function () {
        Route::name('index')->get('index', "LogController@index");
        Route::name('getModuleConfig')->get('getModuleConfig', "LogController@getModuleConfig")->withoutMiddleware(["routes"]);
        Route::name('create')->get('create', function () {
            return Route:: currentRouteName();
        });
        Route::name('store')->post('store', function () {
            return Route:: currentRouteName();
        });
        Route::name('edit')->get('edit', function () {
            return Route:: currentRouteName();
        });
        Route::name('update')->post('update', function () {
            return Route:: currentRouteName();
        });
        Route::name('destroy')->get('destroy/{id}', function ($id) {
            return $id . Route:: currentRouteName();
        });
    });
    //登录日志相关
    Route::name('loginlog.')->prefix('loginlog')->group(function () {
        Route::name('index')->get('index', function () {
            return Route:: currentRouteName();
        });
        Route::name('create')->get('create', function () {
            return Route:: currentRouteName();
        });
        Route::name('store')->post('store', function () {
            return Route:: currentRouteName();
        });
        Route::name('edit')->get('edit', function () {
            return Route:: currentRouteName();
        });
        Route::name('update')->post('update', function () {
            return Route:: currentRouteName();
        });
        Route::name('destroy')->get('destroy/{id}', function ($id) {
            return $id . Route:: currentRouteName();
        });
    });


    //菜单管理
    Route::name('menu.')->prefix('menu')->group(function () {
        Route::name('index')->get('index', "MenuController@index");
        Route::name('create')->get('create', "MenuController@create");
        Route::name('store')->post('store', "MenuController@store")->withoutMiddleware(["routes"]);//权限规则待定
        Route::name('edit')->get('edit/{id}', "MenuController@edit");
        Route::name('update')->post('update/{id}', "MenuController@update")->withoutMiddleware(["routes"]);//权限规则待定
        Route::name('destroy')->get('destroy/{id}', "MenuController@destroy");//不需要删除
        Route::name('check')->get('check', "MenuController@check_route")->withoutMiddleware(["routes"]);//权限规则待定
        Route::name('edit.attach.1')->get('sort/{id}/{sort}', "MenuController@setSort");

    });

    //全局设置
    Route::name('set.')->prefix('set')->group(function () {
        //基础信息
        Route::name('index')->get('baisc/index', 'SetController@index');
        Route::name('create')->post('create', 'SetController@store');
        Route::name('create.attach')->post('baisc/upload', 'SetController@upload');

        //顶部导航
        Route::name('index.attach.1')->get('navigation/index', 'SetController@navigationIndex');

        //用户设置
        Route::name('index.attach.2')->get('user/index', 'SetController@userIndex');

        //微信设置
        Route::name('index.attach.3')->get('wechat/index', 'SetController@wechatIndex');

        //企业微信设置
        Route::name('index.attach.4')->get('company/wechat/index', 'SetController@companyWechatIndex');

        //钉钉设置
        Route::name('index.attach.5')->get('dingTalk/index', 'SetController@dingTalkIndex');

        //云存储 todo 待定
    });


    //课程
    Route::name('course.')->prefix('course')->group(function () {
        Route::name('index')->get('index', 'CourseController@index');
        Route::name('store')->post('store', 'CourseController@store');
        Route::name('upload')->post('upload', 'CourseController@upload');
    });
    //学员
    Route::name('student.')->prefix('student')->group(function () {
        Route::name('index')->get('index', function () {
            return "index";
        });
        Route::name('store')->post('store', function () {
            return "store";
        });
        Route::name('upload')->post('upload', function () {
            return "upload";
        });
    });

    //试题管理
    Route::name('question.')->prefix('question')->group(function () {
        Route::name('index')->get('index', "QuestionController@index");
        Route::name('show')->get('show/{id}', "QuestionController@show");
        Route::name('create')->match(["get", "post"], 'create', "QuestionController@create");
        Route::name('update')->match(["get", "post"], 'update/{id}', "QuestionController@edit");
        Route::name('destroy')->get('destroy', "QuestionController@destroy");
    });

    //题型分类
    Route::name('questionType.')->prefix('questionType')->group(function () {
        Route::name('index')->get('index', "QuestionTypeController@index");
        Route::name('create')->match(["get", "post"], 'create', "QuestionTypeController@create");
        Route::name('update')->match(["get", "post"], 'update/{id}', "QuestionTypeController@edit");
        Route::name('destroy')->get('destroy/{id}', "QuestionTypeController@destroy");
    });

    //试卷管理
    Route::name('examPaper.')->prefix('examPaper')->group(function () {
        Route::name('index')->get('index', "ExamPaperController@index");
        Route::name('create')->match(["get", "post"], 'create', "ExamPaperController@create");
        Route::name('update')->match(["get", "post"], 'update/{id}', "ExamPaperController@edit");
        Route::name('destroy')->get('destroy/{id}', "ExamPaperController@destroy");
    });
});
